package com.testfileupload.uploadimg.design.single;

/**
 * 饿汉式
 * 优点：简单；类装载的时候完成实例化、避免线程同步问题
 * 缺点：类装载的时候完成实例化，没有实现懒加载，如果没有用到，造成内存浪费
 */
public class SingleModel1 {
    public static void main(String[] args) {
        Single instence = Single.getInstence();
        Single instence1 = Single.getInstence();
        System.out.println(instence);
        System.out.println(instence1);
        System.out.println(instence.equals(instence1));
        System.out.println(instence == instence1);
    }
}

class Single {
    /**
     * 内部创建对象实例
     */
    private final static Single single = new Single();

    /**
     * 构造私有化，不能new
     */
    private Single() {
    }

    /**
     * 提供共有静态方法
     * @return
     */
    public static Single getInstence() {
        return single;
    }

}
